<template>
  <div class="container">
    <el-upload
      action=""
      class="upload-demo"
      :auto-upload="false"
      accept=".xlsx, .xls"
      :on-change="handleFileChange1"
    >
      <el-button size="small" type="primary">点击上传</el-button>
    </el-upload>
    <input type="file" @change="handleFileChange" />

    <el-button size="small" @click="handleClick" type="primary">检查</el-button>
    {{ count }}
  </div>
</template>

<script>
import * as XLSX from "xlsx";
import JSZip from "jszip";

function isPiPei(str1, str2) {
  const split = str1.split("");
  const newData = [];
  for (const ite of split) {
    str2.includes(ite) && newData.push(str2.includes(ite));
  }
  return newData.length / split.length > 0.7;
}
function unique(arr) {
  const res = new Map();
  return arr.filter((item) => !res.has(item.原名称) && res.set(item.原名称, 1));
}

export default {
  data() {
    return {
      files: [],
      sheetData: [],
      count: 0,
    };
  },
  methods: {
    handleClick() {
      this.count = 0;
      console.log(this.sheetData);
      console.log(this.files);
      for (const file of this.files) {
        for (const sheetData of unique(this.sheetData)) {
          if (isPiPei(file.name, sheetData.原名称)) {
            console.log(isPiPei(file.name, sheetData.原名称));
            console.log(file.name, sheetData.原名称, this.count);
            this.count++;
          }
          // console.log(sheetData);
        }
      }
      //  console.log( unique(this.sheetData).length);
    },
    handleFileChange1(file) {
      const reader = new FileReader();
      reader.onload = (event) => {
        const data = new Uint8Array(event.target.result);
        const workbook = XLSX.read(data, { type: "array" });
        const sheetName = workbook.SheetNames[0];
        const sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName]);
        console.log(sheetData); // 输出解析后的数据
        this.sheetData = sheetData;
      };
      reader.readAsArrayBuffer(file.raw);
    },
    handleFileChange(event) {
      const file = event.target.files[0];
      if (file) {
        this.readZipFile(file);
      }
    },
    async readZipFile(file) {
      const zip = new JSZip();
      const zipContent = await zip.loadAsync(file);
      const files = [];
      zipContent.forEach((relativePath, zipEntry) => {
          // zipEntry.async("blob").then(function (blob) {
          //   // 图片地址 
          //   const url = URL.createObjectURL(blob);
          // });
        files.push({ name: zipEntry.name });
      });
      console.log(zipContent);
      this.files = files;
    },
    createdNewImage() {},
  },
};
</script>

<style>
:root {
  --primary-color: #4361ee;
  --secondary-color: #6c757d;
  --success-color: #06d6a0;
  --warning-color: #ffd166;
  --danger-color: #ef476f;
  --light-bg: #f8f9fa;
  --dark-bg: #212529;
  --border-color: #dee2e6;
  --card-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

body {
  background: linear-gradient(135deg, #e0f7fa 0%, #f5f7fa 100%);
  min-height: 100vh;
  padding: 20px;
  color: #333;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 30px;
  padding: 20px;
}

h1 {
  font-size: 2.8rem;
  margin-bottom: 10px;
  background: linear-gradient(
    90deg,
    var(--primary-color),
    var(--success-color)
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
}

.subtitle {
  font-size: 1.2rem;
  color: var(--secondary-color);
  max-width: 700px;
  margin: 0 auto 25px;
  line-height: 1.6;
}

.card {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  padding: 30px;
  margin-bottom: 30px;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.card:hover {
  /* transform: translateY(-5px); */
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.card-title {
  font-size: 1.6rem;
  margin-bottom: 25px;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  padding-bottom: 12px;
}

.card-title::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 60px;
  height: 4px;
  background: linear-gradient(
    90deg,
    var(--primary-color),
    var(--success-color)
  );
  border-radius: 2px;
}

.card-title i {
  font-size: 1.8rem;
}

.upload-area {
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  padding: 40px 30px;
  text-align: center;
  background-color: rgba(67, 97, 238, 0.03);
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 25px;
  position: relative;
  overflow: hidden;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--primary-color);
  background-color: rgba(67, 97, 238, 0.08);
}

.upload-icon {
  font-size: 4rem;
  color: var(--primary-color);
  margin-bottom: 20px;
  opacity: 0.8;
}

.upload-text {
  font-size: 1.3rem;
  margin-bottom: 15px;
  font-weight: 500;
}

.upload-hint {
  color: var(--secondary-color);
  font-size: 1rem;
  max-width: 500px;
  margin: 0 auto;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 32px;
  background: linear-gradient(135deg, var(--primary-color), #3a56e6);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-align: center;
  box-shadow: 0 5px 15px rgba(67, 97, 238, 0.3);
  gap: 10px;
}

.btn:hover {
  background: linear-gradient(135deg, #3a56e6, var(--primary-color));
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(67, 97, 238, 0.4);
}

.btn:active {
  transform: translateY(0);
}

.btn-lg {
  padding: 16px 40px;
  font-size: 1.2rem;
}

.btn-secondary {
  background: linear-gradient(135deg, var(--secondary-color), #5a6268);
  box-shadow: 0 5px 15px rgba(108, 117, 125, 0.3);
}

.btn-secondary:hover {
  background: linear-gradient(135deg, #5a6268, var(--secondary-color));
  box-shadow: 0 8px 20px rgba(108, 117, 125, 0.4);
}

.btn-success {
  background: linear-gradient(135deg, var(--success-color), #05b48d);
  box-shadow: 0 5px 15px rgba(6, 214, 160, 0.3);
}

.btn-success:hover {
  background: linear-gradient(135deg, #05b48d, var(--success-color));
  box-shadow: 0 8px 20px rgba(6, 214, 160, 0.4);
}

.btn-group {
  display: flex;
  gap: 20px;
  margin-top: 30px;
  justify-content: center;
  flex-wrap: wrap;
}

.progress-container {
  margin-top: 30px;
  background-color: var(--light-bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.progress-bar {
  height: 14px;
  background: linear-gradient(
    90deg,
    var(--primary-color),
    var(--success-color)
  );
  width: 0%;
  transition: width 0.4s ease;
  border-radius: 12px;
}

.progress-text {
  text-align: center;
  padding: 20px;
  font-size: 1.1rem;
  font-weight: 500;
}

.result-container {
  margin-top: 35px;
}

.result-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  cursor: pointer;
}

.result-content {
  max-height: 500px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

th,
td {
  padding: 16px 20px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  background: linear-gradient(to bottom, #f1f3f9, #e9ecef);
  font-weight: 700;
  color: var(--dark-bg);
}

tr:nth-child(even) {
  background-color: rgba(67, 97, 238, 0.03);
}

tr:hover {
  background-color: rgba(67, 97, 238, 0.08);
}

.preview-img {
  width: 70px;
  height: 70px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.collapsible {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.5s ease;
}

.collapsible.expanded {
  max-height: 500px;
}

.toggle-icon {
  transition: transform 0.3s ease;
  font-size: 1.5rem;
  color: var(--primary-color);
}

.toggle-icon.expanded {
  transform: rotate(180deg);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  gap: 6px;
}

.status-badge::before {
  content: "";
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status-pending {
  background-color: #fff3cd;
  color: #856404;
}

.status-pending::before {
  background-color: #ffc107;
}

.status-success {
  background-color: #d4edda;
  color: #155724;
}

.status-success::before {
  background-color: #28a745;
}

.status-error {
  background-color: #f8d7da;
  color: #721c24;
}

.status-error::before {
  background-color: #dc3545;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 25px;
  margin-top: 35px;
}

.summary-card {
  background: white;
  border-radius: 14px;
  padding: 25px;
  text-align: center;
  box-shadow: var(--card-shadow);
  border: 1px solid rgba(67, 97, 238, 0.1);
  transition: transform 0.3s ease;
}

.summary-card:hover {
  transform: translateY(-5px);
}

.summary-icon {
  font-size: 2.5rem;
  margin-bottom: 15px;
  color: var(--primary-color);
  opacity: 0.8;
}

.summary-number {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--primary-color);
  margin: 10px 0;
}

.summary-label {
  color: var(--secondary-color);
  font-size: 1.1rem;
  font-weight: 500;
}

.instructions {
  background: linear-gradient(
    135deg,
    rgba(67, 97, 238, 0.08),
    rgba(6, 214, 160, 0.08)
  );
  border-left: 5px solid var(--primary-color);
  padding: 25px;
  border-radius: 0 14px 14px 0;
  margin-bottom: 35px;
  position: relative;
  overflow: hidden;
}

.instructions::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
  background: linear-gradient(
    90deg,
    var(--primary-color),
    var(--success-color)
  );
}

.instructions h3 {
  margin-bottom: 20px;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  gap: 10px;
}

.instructions ol {
  padding-left: 30px;
}

.instructions li {
  margin-bottom: 15px;
  line-height: 1.7;
  font-size: 1.05rem;
  position: relative;
}

.instructions li::marker {
  color: var(--primary-color);
  font-weight: bold;
}

.instructions code {
  background-color: rgba(67, 97, 238, 0.1);
  padding: 3px 8px;
  border-radius: 5px;
  font-family: monospace;
  font-size: 0.95rem;
  color: var(--primary-color);
}

.file-info {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.file-info-item {
  background: white;
  padding: 15px 25px;
  border-radius: 10px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
}

.file-info-icon {
  font-size: 1.5rem;
  color: var(--primary-color);
}

footer {
  text-align: center;
  margin-top: 40px;
  padding: 20px;
  color: var(--secondary-color);
  font-size: 0.95rem;
}

@media (max-width: 768px) {
  .btn-group {
    flex-direction: column;
    align-items: center;
  }

  .btn {
    width: 100%;
    max-width: 300px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 20px;
  }

  .upload-area {
    padding: 30px 15px;
  }
}
</style>
